package com.example.springbootfoodsafety.dao;


import com.example.springbootfoodsafety.entity.User;
import com.example.springbootfoodsafety.po.Article;
import com.example.springbootfoodsafety.po.Friends;
import com.example.springbootfoodsafety.po.Speak;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserDao {
    /***
     * 获取某一账号的文章
     * @param id
     * @return
     */
    @Select("SELECT m.id,m.title,m.summary synopsis,m.create_time dateline,m.body,m.view_counts viewCounts,m.img,u.user_name author,u.avatar authorheaderImg from my_article m LEFT JOIN common_user u on m.author_id=u.id WHERE u.id=#{id} and m.static=2 GROUP BY dateline desc ,id desc  LIMIT 6;")
     List<Article> getUserArticle(Integer id);

     List<Speak> addUserSpeak();

    /***
     * 获取到某一篇文章下面的评论
     * @return
     */
    public List<Speak> getUserSpeak(Integer id);
    @Select("select ")
     int getUserChilen();

    @Update("update common_user set user_name=#{uname},sex=#{sex},age=#{age},address=#{address},birthday=#{birthday},email=#{eml} where id =#{id}")
     boolean modifyUser(User user);


/**________________________________好友关注用户功能_____________________________________**/

    @Select("SELECT * from friend where masterId=#{id}")
    List<Friends> getUserFriends(Integer id);
    @Select("select id,user_name uname,age,sex,address,birthday,avatar headImg,if_deleted as 'delete' from common_user WHERE id=#{id}")
    User getAllFriendsUser(Integer id);
    @Insert("insert INTO friend(masterId,friendId) values(#{masterId},#{friendId})")
    boolean addFriends(@Param("masterId") Integer masterId,@Param("friendId") Integer friendId);

}
